#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

#define TAG_NONE 0
#define TAG_BYTE 1
#define TAG_SHORT 2
#define TAG_INT 3
#define TAG_LONG 4
#define TAG_FLOAT 5
#define TAG_DOUBLE 6
#define TAG_BYTE_ARRAY 7
#define TAG_STRING 8
#define TAG_LIST 9
#define TAG_COMPOUND 10
#define TAG_INT_ARRAY 11

typedef struct nbt_list {
	struct nbt_node* node;
	struct nbt_list* next;
	struct nbt_list* prev;
} nbt_list;

typedef struct nbt_node {
	int type;
	char* name;
	union {
		char i8;
		short i16;
		int i32;
		int64_t i64;
		float f32;
		double f64;
		struct byte_array {
			unsigned char* data;
			int size;
		} byte_array;
		struct int_array {
			unsigned int* data;
			int size;
		} int_array;
		char* str;
		nbt_list *list;
	} payload;
} nbt_node;

nbt_node* NbtParse(u8* data, int* size, int force_type);
nbt_node* NbtFindNode(nbt_node* parent, const char* name, bool recursive);
void NbtFree(nbt_node* node);

uint16_t bswap16(uint16_t x);
uint32_t bswap32(uint32_t x);
uint64_t bswap64(uint64_t x);

#ifdef __cplusplus
};
#endif
